package com.feihong.dubbo.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.feihong.dubbo.api.service.StudentService;
import com.feihong.dubbo.model.dto.student.StudentDTO;
import com.feihong.dubbo.model.util.result.Result;
import com.feihong.dubbo.model.util.result.ResultStatusEnum;
import com.feihong.dubbo.model.util.transform.ObjectTransformUtil;
import com.feihong.dubbo.model.vo.student.StudentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhufeihong
 * @since 2019/7/5-5:00
 */
@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {

    @Reference
    private StudentService studentService;

    @ResponseBody
    @RequestMapping("/findByNumber")
    public Result<StudentVO> findByNumber(@RequestParam String studentNumber) {
        if (studentNumber == null) {
            return Result.failed(ResultStatusEnum.ILLEGAL_ARG_EXCEPTION);
        }
        StudentDTO studentDTO = studentService.findByNumber(studentNumber);
        if (studentDTO == null) {
            return Result.successWith(null, ResultStatusEnum.NO_MATCH_DATA);
        }
        StudentVO studentVO = ObjectTransformUtil.copyProperties(studentDTO, StudentVO.class);
        return Result.successWith(studentVO);
    }
}
